package com.skaz.web;

import com.skaz.bean.Page;
import com.skaz.bean.Result;
import com.skaz.entity.Demo;
import com.skaz.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: jungle
 * @Date: 2018/11/2 5:40 PM
 */
@RestController
@RequestMapping("/demo")
public class DemoController extends BaseController {

    @Autowired
    private DemoService demoService;

    @GetMapping("/get/{id}")
    public Demo hello(@PathVariable Long id) {
        return demoService.get(id);
    }

    @GetMapping("/list")
    public List<Demo> list() {
        return demoService.list();
    }

    @GetMapping("/page")
    public Page<Demo> page(@RequestParam(defaultValue = "1") Integer pageNo, @RequestParam(defaultValue = "15")Integer pageSize) {
        return demoService.page(pageNo, pageSize);
    }

    @PostMapping("/create")
    public Result create(String name){
        return demoService.create(name);
    }
}
